<template>
  <div class="page_padding bonus_detail" :class="{ exam_pad: $route.query.type == '2' || $route.query.type == '1' }">
    <MyNavBar @goback="goback" :title="editTitle" />
    <div class="content">
      <p class="result_hint" :class="[info.status == '1' || info.status == '6' ? 'pass' : 'nopass']">
        {{ enmuData(info.status) }}
      </p>
      <div class="bonus-title">
        <div class="bonus-title--one">
          <p class="title--one">加分对象：{{ `${info.orgName}-${info.userName}` }}</p>
        </div>
        <div class="bonus-title--one">
          <p class="title--one">提交时间：{{ info.time }}</p>
        </div>
      </div>
      <div class="list_cont">
        <div class="list">
          <div class="list_text_title">
            <span class="text title-text">{{ activeTab == '1' ? '加' : '减' }}分项名称</span>
          </div>
          <div class="list_con" v-html="removeHtmlStyle(info.boundsName)"></div>
        </div>
        <div class="list">
          <div class="list_text_title">
            <span class="text title-text">{{ activeTab == '1' ? '加' : '减' }}分项说明</span>
          </div>
          <div class="list_con" v-html="removeHtmlStyle(info.boundsRemark)"></div>
        </div>
        <div class="list">
          <div class="list_text_title">
            <span class="text title-text">{{ activeTab == '1' ? '加' : '减' }}分项类别</span>
          </div>
          <div class="list_con" v-html="removeHtmlStyle(info.boundsTypeName)"></div>
        </div>
        <div class="list" v-if="info.tagName">
          <div class="list_text_title">
            <span class="text title-text">{{ info.tagName }}</span>
          </div>
          <div class="list_con">{{ info.boundsLevelName }}</div>
        </div>
        <div class="list" v-if="info.lastTagName && info.lastTagName !== '加分项名称'">
          <div class="list_text_title">
            <span class="text title-text">{{ info.lastTagName }}</span>
          </div>
          <div class="list_con">{{ info.level }}</div>
        </div>
        <div class="list">
          <div class="list_text_title">
            <span class="text title-text">证明材料</span>
          </div>
          <div class="img_annex">
            <ImgUpload v-if="info.albumList.length > 0" :albumList="info.albumList" :entry="false" />
            <p class="fiile_empty" v-if="info.albumList.length == 0">无</p>
          </div>
        </div>
        <div v-if="info.score && (info.status == '0' || info.status == '1')">
          <div class="list">
            <div class="list_text_title">
              <span class="text title-text">评分</span>
            </div>
            <div class="list_con">{{ Number(info.score) }}分</div>
          </div>
          <template>
            <div class="list">
              <div class="list_text_title">
                <span class="text title-text">审核结果</span>
              </div>
              <div class="list_con">{{ enmuData(info.status) }}</div>
            </div>
            <div class="exit_" v-if="info.isCanApprove === '1' && $route.query.type === '2'">
              <div class="exit_btn" @click="exitSubmit">不通过</div>
              <div class="word">提醒：各单位录入结果系统默认审核通过，如有异议可点击“不通过”退回</div>
            </div>
            <div class="list" v-if="info.confirmSuggestion">
              <div class="list_text_title">
                <span class="text title-text">审核意见</span>
              </div>
              <div class="list_con" v-html="removeHtmlStyle(info.confirmSuggestion)"></div>
            </div>
          </template>
        </div>
      </div>
    </div>
    <videoPreview class="video_box" :show="videoPlayShow" :src="videoPlayUrl" @close="videoClose" />

    <van-popup class="popu_suggese" v-model="popupShow" closeable position="bottom">
      <div class="pop_box">
        <van-field
          v-model="confirmSuggestion"
          rows="3"
          autosize
          label=""
          type="textarea"
          placeholder="请输入原因"
          class="pop_field"
          maxlength="128"
          show-word-limit />
        <div class="pop_btn">
          <div class="btn_li" @click="cancelExtraParmas()">取消</div>
          <div class="btn_li" @click="submitData('1')">确定</div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import MyNavBar from '@com/MyNavBar'
import { getBonusPointsDetails, returnBonusPoints } from '@api/api-bonus.js'
import videoPreview from '@com/videoPreview'
import ImgUpload from '@com/ImgUpload'
export default {
  name: 'BonusDetail',
  components: {
    MyNavBar,
    videoPreview,
    ImgUpload,
  },
  props: {
    editTitle: {
      type: String,
      default: '详情',
    },
  },
  data() {
    return {
      stateList: [
        { id: '0', name: '不通过' },
        { id: '1', name: '通过' },
      ],
      id: this.$route.query.id,
      videoPlayShow: false,
      videoPlayUrl: '',
      info: {
        albumList: [],
        boundsName: '',
        boundsRemark: '',
        boundsTypeName: '',
        enclosureList: [],
        userName: '',
        orgName: '',
        title: '',
        tagName: '',
        saBonusListResponse: '',
      },
      keyboardShow: false,
      score: '',
      scoreFix: '',
      popupShow: false,
      confirmSuggestion: '',
      btnType: 0,
      chooseStatus: '1',
      examineDataList: [
        {
          name: '审定通过',
          id: '1',
        },
        {
          name: '审定不通过',
          id: '0',
        },
        {
          name: '退回修改',
          id: '3',
        },
      ],
      userInfo: JSON.parse(localStorage.userInfo),
      isUnitLeader: false,
      activeTab: '1',
      popupShow: false,
    }
  },
  computed: {},
  watch: {},
  created() {
    this.activeTab = this.$route.query.applyType
  },
  mounted() {
    this.getApplyParmas()
  },
  methods: {
    goback() {
      this.$router.go(-1)
    },
    removeHtmlStyle(html) {
      const rel = /style\s*?=\s*?([‘"])[\s\S]*?\1/g
      let newHtml = ''
      if (html) {
        newHtml = html.replace(rel, '')
      }
      return newHtml
    },
    enmuData(code) {
      if (code) {
        const nameArr = this.stateList.filter(item => {
          return item.id === code
        })
        if (nameArr.length > 0) {
          return nameArr[0].name
        } else {
          return '--'
        }
      }
    },
    getApplyParmas() {
      getBonusPointsDetails({
        id: this.id,
      }).then(res => {
        if (res.status === 200) {
          this.info = { ...res.data }
          this.info.albumList.push(...this.info.enclosureList)
          this.score = Number(this.info.score)
          this.scoreFix = this.info.score
        }
      })
    },

    // 审核结果类型切换
    resultChange({ id }) {
      if (this.chooseStatus !== id) {
        this.chooseStatus = id
        this.confirmSuggestion = ''
      }
    },
    // 预览图片
    previewImage(index) {
      const imagesArr = this.albumList.map(item => item.thumbnailPath)
      this.$ImagePreview({
        images: imagesArr,
        startPosition: index,
        loop: false,
        onChange(index) {
          if (index === imagesArr.length - 1 && imagesArr.length > 1) {
            this.$toast('这是最后一张了')
          }
        },
      })
    },
    // 视频播放
    playVideoItem(item) {
      this.videoPlayUrl = item.sourcePath
      this.videoPlayShow = true
    },
    // 视频关闭
    videoClose() {
      this.videoPlayUrl = ''
      this.videoPlayShow = false
    },
    exitSubmit() {
      this.popupShow = true
    },
    cancelExtraParmas() {
      this.confirmSuggestion = ''
      this.popupShow = false
    },
    submitData() {
      if (!this.confirmSuggestion) return this.$toast.fail('请填写审核意见')
      this.saveData()
    },
    saveData() {
      returnBonusPoints({
        id: this.info.id,
        confirmSuggestion: this.confirmSuggestion,
        result: '0',
      }).then(res => {
        if (res.status === 200) {
          this.$toast.success('审批成功')
          this.popupShow = false
          setTimeout(() => {
            this.$router.go(-1)
          }, 500)
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.exam_pad {
  padding-bottom: 35px;
}
.bonus_detail {
  .text_tips {
    color: #999999;
    background-color: rgba(230, 127, 43, 0.1);
    padding: 5px 8px;
  }
  .bonus-title {
    background-color: #fff;
    margin-bottom: 12px;
    padding: 10px 15px 0 15px;
  }
  .bonus-title--one {
    display: flex;
    align-items: center;
    padding-bottom: 15px;
  }
  .title--one {
    width: 60%;
  }
  .title--two {
    width: 40%;
  }
}
.page_padding {
  background: #f5f5f5;
  .content {
    .pass {
      background: #fff;
      color: #3fa83f;
    }
    .nopass {
      background: #fdf1dd;
      color: #86642c;
    }
    .result_hint {
      width: 100%;
      text-align: center;
      padding: 8px;
      font-size: 16px;
      background-color: rgba(230, 127, 43, 0.1);
    }
    .list_cont {
      margin-top: 15px;
      background: #fff;
      padding: 16px;
      word-break: break-all;
      .con_tips {
        line-height: 17px;
        color: #a7a7a7;
        p {
          margin-bottom: 6px;
        }
      }
    }
    .cart {
      margin-top: 32px;

      .list:not(:first-of-type) {
        padding-top: 0;
      }
      .list_con {
        margin-bottom: 20px;
      }
      .explain {
        line-height: 17px;
        color: #888;
      }
    }
    .list {
      margin-bottom: 16px;
      .list_text_title {
        font-weight: bold;
        color: #333;
        margin-bottom: 10px;
        .text {
          background-image: linear-gradient(#ffffff 50%, #e5d2b4);
        }
      }
      .right_btn_result {
        display: flex;
        justify-content: space-between;
        span {
          border: 1px solid #a7a7a7;
          border-radius: 2px;
          width: 80px;
          height: 30px;
          line-height: 30px;
          color: #a7a7a7;
          text-align: center;
          cursor: pointer;
        }
        .choose_cative {
          color: #c09144;
          border-color: #c09144;
        }
      }
      .list_con {
        font-size: 14px;
        line-height: 25px;
        color: #333333;
      }
      // 图片附件
      .img_annex {
        padding-top: 10px;
        .img {
          margin-bottom: 6px;
        }
        .fiile_empty {
          color: #333;
          font-size: 14px;
        }
      }
    }
    .exit_ {
      .exit_btn {
        height: 32px;
        background: #0f61d5;
        border-radius: 4px;
        line-height: 32px;
        text-align: center;
        color: #ffffff;
        width: 70px;
      }
      .word {
        margin-top: 5px;
        color: #999999;
      }
    }
  }
  .van-cell::after {
    border-bottom: none;
  }
  /deep/.van-popup {
    padding: 10px 5px 25px 5px;
    .pop_box {
      margin-top: 15px;

      .pop_btn {
        flex: 1;
        padding: 0 15px;
        height: 36px;
        width: 100%;
        margin: 0 auto;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .btn_li {
          text-align: center;
          color: #ffffff;
          height: 40px;
          background: #0f61d5;
          border-radius: 5px;
          line-height: 40px;
          width: 25%;
          &:first-child {
            background: #f5f5f5;
            color: #999999;
          }
        }
      }
    }
    .van-popup__close-icon--top-right {
      top: 5px;
    }
  }
  /deep/.van-field__body {
    padding: 5px;
    .pop_field {
      margin-top: 15px;
    }
    .van-field__control {
      border: 1px solid #999;
      border-radius: 6px;
      padding: 5px 15px;
    }
  }
  .van-cell::after {
    border-bottom: none;
  }
}
</style>
